package com.miyake.dsp.osa.lab.wrapper;

import com.miyake.dsp.ComplexArray;
import com.miyake.dsp.osa.OsaCsv;
import com.miyake.dsp.osa.lab.Calculator;
import com.miyake.dsp.osa.lab.LabUiAnnotation;
import com.miyake.dsp.osa.lab.FileSetting;

@LabUiAnnotation(caption="MS9740A CSV Reader")
public class Ms9740aCsvWrapper extends Calculator {
	public static final String OUTPUTLEVEL = "Level";
	public static final String OUTPUTWAVELENGTH = "Wavelength";
	private FileSetting setting;
	
	public Ms9740aCsvWrapper(FileSetting setting) {
		this.setting = setting;
		initOutput(OUTPUTWAVELENGTH);
		initOutput(OUTPUTLEVEL);
	}
	
	@Override
	public synchronized void process() {
		OsaCsv csv = new OsaCsv(setting.getFilePath());
		this.setOutput(OUTPUTLEVEL, new ComplexArray(csv.getLevel()));
		double start = csv.getSetting().getStartWavelength();
		double step = csv.getSetting().getSpanWavelength() / (csv.getSetting().getSamplingPoints()-1);
		double[] x = new double[csv.getSetting().getSamplingPoints()];
		for (int i = 0; i < x.length; i++) {
			x[i] = start + step * (double)i;
		}
		this.setOutput(OUTPUTWAVELENGTH, new ComplexArray(x));
	}

	@Override
	public Object getSetting() {
		return setting;
	}

}
